package com.pybox.api;

import com.pybox.service.TDictDataService;
import com.pybox.dto.TDictDataDto;

import com.pybox.dto.Result;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.*;

/**
* 描述：TDictData Api
* @author wuyingkai
* @date 2018-09-15
*/

@Slf4j
@RequestMapping("/TDictData")
@ApiIgnore
@Api(tags = "TDictData管理接口", description = "TDictData管理接口")
@RestController
public class TDictDataApi {

    @Autowired
    private TDictDataService service;

    @ApiOperation(value = "创建TDictData", notes = "创建TDictData")
    @RequestMapping(value = "/create", method = RequestMethod.POST)
    public Result<Boolean> save(@RequestBody TDictDataDto dto) {
        service.create(dto);
        return Result.ok(true);
    }

    @ApiOperation(value = "删除TDictData", notes = "删除TDictData")
    @RequestMapping(value = "/delete/{id}", method = RequestMethod.DELETE)
    @ApiImplicitParam(name = "id", value = "TDictData id", dataType = "String", paramType = "path")
    public Result<Boolean> delete(@PathVariable("id") Integer id) {
        service.delete(id);
        return Result.ok(true);
    }

    @ApiOperation(value = "更新TDictData", notes = "更新TDictData")
    @RequestMapping(value = "/update/{id}", method = RequestMethod.PUT)
    @ApiImplicitParam(name = "id", value = "TDictData id", dataType = "String", paramType = "path")
    public Result<Boolean> update(@PathVariable("id") Integer id, @RequestBody TDictDataDto dto) {
        service.update(id, dto);
        return Result.ok(true);
    }

    @ApiOperation(value = "查询TDictData", notes = "查询TDictData")
    @RequestMapping(value = "/detail/{id}", method = RequestMethod.GET)
    @ApiImplicitParam(name = "id", value = "TDictData id", dataType = "String", paramType = "path")
    public Result<TDictDataDto> detail(@PathVariable("id") Integer id) {

        return Result.ok(service.detail(id));
    }

    @ApiOperation(value = "分页查询TDictData", notes = "分页查询TDictData")
    @RequestMapping(value = "/search", method = RequestMethod.GET)
    @ApiImplicitParams({
           @ApiImplicitParam(name = "dictCode", value = "dictCode", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "dictSort", value = "dictSort", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "dictLabel", value = "dictLabel", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "dictValue", value = "dictValue", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "dictType", value = "dictType", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "cssClass", value = "cssClass", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "listClass", value = "listClass", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "isDefault", value = "isDefault", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "status", value = "status", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "createBy", value = "createBy", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "createTime", value = "createTime", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "updateBy", value = "updateBy", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "updateTime", value = "updateTime", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "remark", value = "remark", dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "pageNo", value = "pageNo", dataType = "int", paramType = "query"),
        @ApiImplicitParam(name = "pageSize", value = "pageSize", dataType = "int", paramType = "query")
    })
    public Result<Page<TDictDataDto>> page(
                        @RequestParam(required = false) String dictCode,
                        @RequestParam(required = false) String dictSort,
                        @RequestParam(required = false) String dictLabel,
                        @RequestParam(required = false) String dictValue,
                        @RequestParam(required = false) String dictType,
                        @RequestParam(required = false) String cssClass,
                        @RequestParam(required = false) String listClass,
                        @RequestParam(required = false) String isDefault,
                        @RequestParam(required = false) String status,
                        @RequestParam(required = false) String createBy,
                        @RequestParam(required = false) String createTime,
                        @RequestParam(required = false) String updateBy,
                        @RequestParam(required = false) String updateTime,
                        @RequestParam(required = false) String remark,
                    @RequestParam(required = true) Integer pageNo,
                    @RequestParam(required = true) Integer pageSize) {

        Map<String, String> params = new HashMap<>();
                params.put("dictCode",dictCode);
                params.put("dictSort",dictSort);
                params.put("dictLabel",dictLabel);
                params.put("dictValue",dictValue);
                params.put("dictType",dictType);
                params.put("cssClass",cssClass);
                params.put("listClass",listClass);
                params.put("isDefault",isDefault);
                params.put("status",status);
                params.put("createBy",createBy);
                params.put("createTime",createTime);
                params.put("updateBy",updateBy);
                params.put("updateTime",updateTime);
                params.put("remark",remark);
        return Result.ok(service.page(pageNo, pageSize, params));
    }
}